﻿using AutoMapper.Internal.Mappers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace Himp.Platform
{
    /// <summary>
    /// 
    /// </summary>
    public class AppBizflowService : CrudAppService<AppBizflow, AppBizflowDto, Guid, AppBizflowInput, AppBizflowCreateDto, AppBizflowUpdateDto>
    {
        /// <summary>
        /// 
        /// </summary>
        private IRepository<AppBizflow, Guid> _appBizflowRepository;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="projectConfigRepository"></param>
        public AppBizflowService(IRepository<AppBizflow, Guid> appBizflowRepository) : base(appBizflowRepository)
        {
            _appBizflowRepository = appBizflowRepository;
        }

        /// <summary>
        /// 获取消息业务类别
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public override async Task<PagedResultDto<AppBizflowDto>> GetListAsync(AppBizflowInput input)
        {
            var iQuery = await _appBizflowRepository.GetQueryableAsync();

            if (input.Pi == 0)
            {
                var itemsDto = ObjectMapper.Map<List<AppBizflow>, List<AppBizflowDto>>(iQuery.ToList());

                return new PagedResultDto<AppBizflowDto>(itemsDto.Count, itemsDto);
            }
            else
            {
                var totalCount = iQuery.Count();
                var items = iQuery.Page(input.Pi, input.Ps);
                var itemsDto = ObjectMapper.Map<List<AppBizflow>, List<AppBizflowDto>>(items.ToList());

                return new PagedResultDto<AppBizflowDto>(totalCount, itemsDto);
            }
        }
    }
}
